//
//  MyServerVC.m
//  shortvideoplay
//
//  Created by tikeios_002 on 2024/9/26.
//

#import "MyServerVC.h"
#import "my_settingTableViewCell.h"
#import "DJMyWallVC.h"
#import "QZHongBaoDetailsVC.h"
#import "DJMyCreatorCenterCViewController.h"
#import "DJAttestationzVC.h"
#import "QZSeeHistoryVC.h"
#import "DJMyFeedBackVC.h"
#import "MyAboutSettingVC.h"
#import "MyServerHeaderView.h"
#import "MyShortVideoSettingVC.h"
#import "MyAcountSettingVC.h"
#import "MyShareListVC.h"
#import "CSJADLoading.h"

@interface MyServerVC ()<UITableViewDelegate,UITableViewDataSource>
@property (strong,nonatomic)NSArray * listArr;
@property (strong ,nonatomic) UITableView * settingtableView;
@end

@implementation MyServerVC

- (void)showOldAddNavViewToMainOldView1{
    UIView * oldBgSS = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    oldBgSS.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:oldBgSS];
    
    UIButton * sendBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreen_W-75, kStatusBarHeight+10, 60, 46)];
    sendBtn.layer.cornerRadius = 3;
    sendBtn.backgroundColor = [UIColor whiteColor];
    [sendBtn setTitle:@"发送" forState:UIControlStateNormal];
    [sendBtn setTitleColor:ColorHex(@"#333333") forState:UIControlStateNormal];
    sendBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [sendBtn addTarget:self action:@selector(sendTap) forControlEvents:UIControlEventTouchUpInside];
    [oldBgSS addSubview:sendBtn];
    
    UIView * sendBg = [[UIView alloc]initWithFrame:CGRectMake(15, kStatusBarHeight+66, KScreen_W-30, (KScreen_H-KSafeAreaBottomHeight-25-(kStatusBarHeight+66))/2)];
    sendBg.backgroundColor = [UIColor whiteColor];
    sendBg.layer.cornerRadius = 3;
    [oldBgSS addSubview:sendBg];
    
    UILabel * sendTip = [[UILabel alloc]initWithFrame:CGRectMake(0, (sendBg.frame.size.height-40)/2, sendBg.frame.size.width, 40)];
    sendTip.text = @"发送区";
    sendTip.textColor = ColorHex(@"#f0f0f0");
    sendTip.textAlignment = NSTextAlignmentCenter;
    sendTip.font = [UIFont systemFontOfSize:28];
    [sendBg addSubview:sendTip];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"服务中心";
    if([[QZUserInfoModel share].invite_switch intValue] == 1){
        _listArr = @[@{@"title":@"钱包功能",@"list":@[@{@"titleName":@"我的钱包",@"imgName":@"ico_setting_qiangbao_wite"},@{@"titleName":@"我的金币",@"imgName":@"ico_setting_jbdh_wite"}]},@{@"title":@"视频创作",@"list":@[@{@"titleName":@"视频创作中心",@"imgName":@"ico_setting_chuangzhuo_wite"},@{@"titleName":@"视频创作认证",@"imgName":@"ico_setting_renzheng_wite"}]},@{@"title":@"短剧功能",@"list":@[@{@"titleName":@"短剧浏览",@"imgName":@"ico_setting_dj_his_wite"},@{@"titleName":@"短剧收藏",@"imgName":@"ico_setting_dj_shoucang_wite"}]},@{@"title":@"常用功能",@"list":@[@{@"titleName":@"功能设置",@"imgName":@"ico_setting_zhanghao_wite"},@{@"titleName":@"我的邀请",@"imgName":@"ico_setting_yaoqing_wite"},@{@"titleName":@"视频浏览",@"imgName":@"ico_setting_lishi_wite"},@{@"titleName":@"意见反馈",@"imgName":@"ico_setting_yijingfangkui_wite"},@{@"titleName":@"关于APP",@"imgName":@"ico_setting_guanyu_wite"}]}];
    }else{
        _listArr = @[@{@"title":@"钱包功能",@"list":@[@{@"titleName":@"我的钱包",@"imgName":@"ico_setting_qiangbao_wite"},@{@"titleName":@"我的金币",@"imgName":@"ico_setting_jbdh_wite"}]},@{@"title":@"视频创作",@"list":@[@{@"titleName":@"视频创作中心",@"imgName":@"ico_setting_chuangzhuo_wite"},@{@"titleName":@"视频创作认证",@"imgName":@"ico_setting_renzheng_wite"}]},@{@"title":@"短剧功能",@"list":@[@{@"titleName":@"短剧浏览",@"imgName":@"ico_setting_dj_his_wite"},@{@"titleName":@"短剧收藏",@"imgName":@"ico_setting_dj_shoucang_wite"}]},@{@"title":@"常用功能",@"list":@[@{@"titleName":@"功能设置",@"imgName":@"ico_setting_zhanghao_wite"},@{@"titleName":@"视频浏览",@"imgName":@"ico_setting_lishi_wite"},@{@"titleName":@"意见反馈",@"imgName":@"ico_setting_yijingfangkui_wite"},@{@"titleName":@"关于APP",@"imgName":@"ico_setting_guanyu_wite"}]}];
    }

    self.settingtableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KScreen_W, self.view.frame.size.height-KTab_H-50)];
    self.settingtableView.sectionHeaderHeight= 0;
    self.settingtableView.sectionFooterHeight= 0;
    self.settingtableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.settingtableView.backgroundColor = viewback_black;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:self.settingtableView];
    self.settingtableView.delegate = self;
    self.settingtableView.dataSource = self;
    
    UIButton * loginOut = [[UIButton alloc]initWithFrame:CGRectMake(15, self.view.frame.size.height-KTab_H-48, KScreen_W-30, 44)];
    loginOut.backgroundColor = MainColor;
    loginOut.layer.cornerRadius = 22;
    [loginOut setTitle:@"退出或切换账号" forState:UIControlStateNormal];
    [loginOut setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    loginOut.titleLabel.font = FontMedium(14);
    [loginOut addTarget:self action:@selector(loginOutTap) forControlEvents:UIControlEventTouchUpInside];
       UILabel * oldshowSSSSTip6 = [[UILabel alloc]init];
    oldshowSSSSTip6.clipsToBounds = YES;
    oldshowSSSSTip6.text = @"kass显示区";
    oldshowSSSSTip6.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip6.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip6.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip6.hidden = YES;
    [self.view addSubview:oldshowSSSSTip6];
    [self.view addSubview:loginOut];
    
    [self.settingtableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_offset(0);
        make.bottom.mas_offset(-50-KSafeAreaBottomHeight);
    }];
    [loginOut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_offset(0);
        make.bottom.mas_offset(-KSafeAreaBottomHeight);
        make.height.mas_offset(44);
    }];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.listArr.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray * list = self.listArr[section][@"list"];
    return list.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    my_settingTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"my_cell"];
    if (cell == nil) {
        cell = [[my_settingTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"setting_cell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell settingConfig:self.listArr[indexPath.section][@"list"][indexPath.row]];
    return cell;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    MyServerHeaderView * header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"header"];
    if(header == nil){
        header = [[MyServerHeaderView alloc]initWithReuseIdentifier:@"header"];
    }
    header.titleLabel.text = self.listArr[section][@"title"];
    return header;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 25;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([self.listArr[indexPath.section][@"list"][indexPath.row][@"titleName"] isEqualToString:@"我的钱包"]){
        DJMyWallVC * about = [DJMyWallVC new];
        [self.navigationController pushViewController:about animated:YES];
    }else if ([self.listArr[indexPath.section][@"list"][indexPath.row][@"titleName"] isEqualToString:@"我的金币"]){
        QZHongBaoDetailsVC * about = [QZHongBaoDetailsVC new];
        [self.navigationController pushViewController:about animated:YES];
    }else if ([self.listArr[indexPath.section][@"list"][indexPath.row][@"titleName"] isEqualToString:@"视频创作中心"]){
        DJMyCreatorCenterCViewController * about = [DJMyCreatorCenterCViewController new];
        [self.navigationController pushViewController:about animated:YES];
    }else if ([self.listArr[indexPath.section][@"list"][indexPath.row][@"titleName"] isEqualToString:@"视频创作认证"]){
        DJAttestationzVC * about = [DJAttestationzVC new];
        [self.navigationController pushViewController:about animated:YES];
    }else if ([self.listArr[indexPath.section][@"list"][indexPath.row][@"titleName"] isEqualToString:@"短剧浏览"]){
        MyShortVideoSettingVC * shortVC = [[MyShortVideoSettingVC alloc]init];
        shortVC.shortType = 0;
        [self.navigationController pushViewController:shortVC animated:YES];
    }else if ([self.listArr[indexPath.section][@"list"][indexPath.row][@"titleName"] isEqualToString:@"短剧收藏"]){
        MyShortVideoSettingVC * shortVC = [[MyShortVideoSettingVC alloc]init];
        shortVC.shortType = 1;
        [self.navigationController pushViewController:shortVC animated:YES];
    }else if ([self.listArr[indexPath.section][@"list"][indexPath.row][@"titleName"] isEqualToString:@"功能设置"]){
        MyAcountSettingVC * vc = [[MyAcountSettingVC alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }else if ([self.listArr[indexPath.section][@"list"][indexPath.row][@"titleName"] isEqualToString:@"视频浏览"]){
        QZSeeHistoryVC * view = [[QZSeeHistoryVC alloc] init];
        [self.navigationController pushViewController:view animated:YES];
    }else if ([self.listArr[indexPath.section][@"list"][indexPath.row][@"titleName"] isEqualToString:@"意见反馈"]){
        DJMyFeedBackVC * view = [[DJMyFeedBackVC alloc]init];
        [self.navigationController pushViewController:view animated:YES];
    }else if ([self.listArr[indexPath.section][@"list"][indexPath.row][@"titleName"] isEqualToString:@"关于APP"]){
        MyAboutSettingVC * view = [[MyAboutSettingVC alloc]init];
        [self.navigationController pushViewController:view animated:YES];
    }else if ([self.listArr[indexPath.section][@"list"][indexPath.row][@"titleName"] isEqualToString:@"我的邀请"]){
        MyShareListVC * list = [[MyShareListVC alloc]init];
        [self.navigationController pushViewController:list animated:YES];
    }
    
}
- (void)loginOutTap{
    KWeakSelf
    [[BSystemAlert shared] showAlertWithTitle:NSLocalizedString(@"温馨提示", nil) message:NSLocalizedString(@"是否确定要退出登录吗？", nil) userData:nil cancelTitle:NSLocalizedString(@"取消", nil) actions:@[NSLocalizedString(@"退出", nil)] actionBlock:^(id  _Nonnull userData, NSString * _Nonnull actionTitle) {
        if ([actionTitle isEqualToString:NSLocalizedString(@"退出", nil)]) {
            KMutableDic(sendDic)
            [YBNetBase userLogoffRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
                if(code == 200){
                    [CSJADLoading dj_SignOutWithPaySecretKey];
                    [QZUserInfoModel cleanUserData];
                    [YBMsgPop showPop:@"账号已退出"];
                    [weakSelf saveToken];
                }else{
                    [YBMsgPop showPop:msg];
                }
            }];
        }
    }];
}
- (void)saveToken{
    KMutableDic(sendDic)
    sendDic[@"device_token"] = [QZUserInfoModel share].pushToken;
    sendDic[@"is_open"] = @([QZUserInfoModel share].lastPushStatus);
    [YBNetBase saveDeviceTokenRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
        
    }];
}
@end
